//
//  CHInformCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/8/2.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHInformCell.h"
@interface CHInformCell()
@property (nonatomic ,strong) UILabel *titleLabel;
@property (nonatomic ,strong) UILabel *timeLabel;

@end
@implementation CHInformCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHInformCell";
    CHInformCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CHInformCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self buildUI];
        
    }
    return self;
    
}

-(void)buildUI{
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont boldSystemFontOfSize:14];
    titleLabel.textColor = [UIColor colorWithHexString:@"333333" alpha:1.0f];
    titleLabel.numberOfLines = 0;
    [self addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.font= [UIFont systemFontOfSize:12];
    timeLabel.textColor = [UIColor colorWithHexString:@"888888" alpha:1.0f];
    [self addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    
}

-(void)setModel:(CHNoticeModel *)model{
    _model = model;
    self.titleLabel.text = model.title;
    CGSize maxSize = CGSizeMake(UIScreenW -2*10, MAXFLOAT);
    NSDictionary *attr = @{NSFontAttributeName:[UIFont systemFontOfSize:14]};
    CGSize titleSize = [self boundingRectWithSize:maxSize attributes:attr text:model.title];
    self.titleLabel.frame = CGRectMake(10, 10, UIScreenW -20, titleSize.height);
    self.timeLabel.text = [model.publishtime substringToIndex:11];
    self.timeLabel.frame = CGRectMake(10, CGRectGetMaxY(self.titleLabel.frame) +10, UIScreenW - 20, 30);
    
    
}


- (CGSize)boundingRectWithSize:(CGSize)maxSize attributes:(NSDictionary *)attr text:(NSString *)text
{
    return [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attr context:nil].size;
}






@end
